<?php 
class Application_Model_Tracking extends Application_Model_DomainObject {
    
    protected $_id;
    
    protected $_objectType; //跟踪类型

    protected $_objectId; //关联Id
    
    protected $_dateAdd;//创建时间
        
    protected $_operator;//添加人
    
    protected $_content;//内容
    
    protected $_isUserVisible;  //用户是否可见
    
    protected $_operateType;    //操作类型
    
    protected $_shipId; //物流Id


    /**
     * 用户不可见
     */
    const User_None = 0;
    /**
     * 用户可见
     */
    const User_Block = 1;
    /**
     * 拆分操作
     */
    const Type_Split = 101;
    /**
     * 合并操作
     */
    const Type_Merge = 102;
    
    
    /**
     * 退换货地址
     */
    const Type_Address = 94;
    /**
     * 悠奇发货运费
     */
    const Type_ReChangeMoney = 95;
    /**
     * 悠奇发货物流
     */
    const Type_ReChangeLogistics = 96;
    /**
     * 卖家发货物流
     */
    const Type_ReissueLogistics = 97;
    /**
     * 异常追踪
     */
    const Type_Quality = 98;
    /**
     * 退货退款
     */
    const Type_ReturnMoney = 103;

    
    public function getTypeName()
    {
        return Application_Model_DomainobjectType::getObjectItem($this->_objectType);
    }
    
    public static function getUserVisibleAll()
    {
        return array(
                   self::User_Block => "可见"
                ,  self::User_None => "不可见"
        );
    }

    public function getIsUser()
    {
        switch ($this->_isUserVisible) {
            case self::User_Block:
                return "可见";
                break;
            default:
                return "不可见";
                break;
        }
    }


    public static function addTrack($objectType,$objectId,$operator,$content,$isUserVisible,$operateType,$dateAdd,$shipId = null)
    {
        $trackingItem = new Application_Model_Tracking();
        $trackingItem->objectType = $objectType;
        $trackingItem->objectId = $objectId;
        $trackingItem->dateAdd = $dateAdd;
        $trackingItem->operator = $operator;
        $trackingItem->content = $content;
        $trackingItem->isUserVisible = $isUserVisible;
        $trackingItem->operateType = $operateType;
        $trackingItem->shipId = $shipId;
        $trackingItem->save();
    }


    public static function getOneByObjectTypeIdOperateType($objectType,$objectId,$operateType)
    {
        return self::getDao()->queryOne(array("objectType = "=>$objectType," and objectId = "=>$objectId," and operateType = "=>$operateType));
    }
    public static function getAllByObjectTypeIdOperateType($objectType,$objectId,$operateType)
    {
        return self::getDao()->queryAll(array("objectType = "=>$objectType," and objectId = "=>$objectId," and operateType = "=>$operateType));
    }
    public static function getAllByObjectTypeId($objectType,$objectId)
    {
        return self::getDao()->queryAll(array("objectType = "=>$objectType," and objectId = "=>$objectId),'id desc');
    }
    public static function byUserBlockGetAllByObjectTypeId($objectType,$objectId)
    {
        return self::getDao()->queryAll(array("objectType = "=>$objectType," and objectId = "=>$objectId," and isUserVisible = "=>self::User_Block));
    }
    public static function getByWayIdInteriorType($objectId,$interior)
    {
        return self::getDao()->queryOne(array("objectId = "=>$objectId," and operateType = "=>$interior ));
    }
    public  function getObjectTypeName()
    {
         $ret = Application_Model_DomainobjectType::load($this->_objectType);
         return $ret->name;
    }
    public static function getTrackbyobjectId($objectId)
    {
          return self::getDao()->queryAll(array("objectId"=> $objectId),"id desc");
    }
    
    public function getShipItem()
    {
        return Application_Model_shipType::load($this->_shipId);
    }
    
    public static function getOneByObjectTypeOperateTypeContent($objectType,$operateType,$content)
    {
        return self::getDao()->queryOne(array("objectType = "=> $objectType," and operateType = "=>$operateType," and content = " => $content));
    }
}